package edu.suse.service.impl;

import edu.suse.common.base.RespResult;
import edu.suse.entity.SysMenu;
import edu.suse.mapper.SysMenuMapper;
import edu.suse.service.SysMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysMenuServiceImpl implements SysMenuService {
    @Resource
    private SysMenuMapper sysMenuMapper;
    @Override
    public RespResult queryMenuListAll(){
        List<SysMenu> sysMenuList = sysMenuMapper.queryMenuListAll();
        return RespResult.success(sysMenuList);
    }

    @Override
    public RespResult findMenu(String status, String title, String url) {
        List<SysMenu> sysMenuList = sysMenuMapper.findMenuOR(status,title,url);
        return RespResult.success(sysMenuList);
    }
// 插入
    @Override
    public RespResult InsertMenu(String perms,String title,String url,String pid,String icon) {
        try{
            sysMenuMapper.addMenu(perms,title,url,pid,icon);


            return RespResult.success("success");

        }catch (Exception e){
            return RespResult.error(-1,"插入失败","");

        }

    }
    //通过id 查找
    @Override
    public RespResult findMenuById(String id) {
        try{
            SysMenu sysMenu = sysMenuMapper.findMenuById(id);


            return RespResult.success(sysMenu);

        }catch (Exception e){
            return RespResult.error(-1,"插入失败","");

        }

    }
    //更新
    @Override
    public RespResult updatemenu(String id, String perms,String title,String url,String pid,String icon) {
        try{
            sysMenuMapper.updatemenuByid(id,perms,title,url,pid,icon);


            return RespResult.success("success");

        }catch (Exception e){
            return RespResult.error(-1,"插入失败","");

        }

    }

    @Override
    public RespResult deletemenu(String id) {
        try{
            sysMenuMapper.deleteMenuById(id);
            return RespResult.success("删除成");

        }catch (Exception e){
            return RespResult.error(-1,"删除失败","");

        }
    }


}
